package com.rr;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.rr.util.MemoryUsageUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author RR
 * @date 2025/1/18 22:36
 */
public class Demo3WriteWithoutClassTest {
    public static void main(String[] args) {
        String filePath = "./test.xlsx";
        List<List<String>> header = getHeader();
        try (ExcelWriter write = EasyExcel.write(filePath).build();){
            WriteSheet sheet1 = EasyExcel.writerSheet(0).sheetName("sheet1").head(header).build();
            for (int i = 0; i < 2; i++) {
                write.write(getDataList(), sheet1);
            }
        }
        MemoryUsageUtils.printThreadInfo();
    }

    private static List<List<String>> getHeader() {
        List<List<String>> header = new ArrayList<>();
        header.add(Collections.singletonList("列1"));
        header.add(Collections.singletonList("列2"));
        header.add(Collections.singletonList("列3"));
        return header;
    }

    private static List<List<String>> getDataList() {
        List<List<String>> dataList = new ArrayList<>();
        dataList.add(Arrays.asList("值1.1", "值1.2", "值1.3"));
        dataList.add(Arrays.asList("值2.1", "值2.2", "值2.3"));
        dataList.add(Arrays.asList("值3.1", "值3.2", "值3.3"));
        return dataList;
    }
}
